<!-- 编辑弹窗 -->
<template>
    <div class="ele-body">
      <el-card>
        <ele-pro-table ref="table"  row-key="id" :columns="warehouseItemColumns"  :datasource="datasource"    :height="tableHeight" :full-height="tableFullHeight">
          <template slot="outOrderNo" slot-scope="{ row }"  >
            <el-link  type="primary"   @click="clickbillNo(row)" >{{ row.outOrderNo }}</el-link>
          </template>
        </ele-pro-table>
      </el-card>
    </div>
</template>
  <script>

  //初始化对像
  import { removePageTab } from '@/utils/page-tab-util';
  import { QuerySaleoutorderByCondition } from '@/api/businesshandling/saleoutmanger';

  export default {
    name: 'SaleOutOrderList',
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 修改回显的数据
      data: Object,
    },
    data() {
      return {
        // 表单数据
        form: {},
        fixedHeight:true,
        // 提交状态
        loading: false,
        // 是否是修改
        isUpdate: false,
        // 表格列配置
        warehouseItemColumns: [
          {columnKey: 'index', type: 'index', width: 50, align: 'center', showOverflowTooltip: true, fixed: 'left', label:'序号',},
          {prop: 'outOrderNo', label: '出库单号',slot:'outOrderNo', showOverflowTooltip: true,align: 'center',sortable:'outOrderNo' },
          {prop: 'customerName', label: '客户名称',  showOverflowTooltip: true, align: 'center'},
          {prop: 'qtyTotal', label: '数量',  showOverflowTooltip: true, align: 'center',sortable:'qtyTotal'},
          {prop: 'commissionAmountTotal', label: '提成金额',showOverflowTooltip: true, align: 'center',},
          {prop: 'currencyDesc', label: '币种', showOverflowTooltip: true, align: 'center'},
          {prop: 'rate', label: '汇率', showOverflowTooltip: true, align: 'center',sortable:'rate'},
          {prop: 'commissionAmountCnTotal', label: '提成金额(￥)',  showOverflowTooltip: true, align: 'center'},
          {
            prop: 'orderDate', label: '订单日期', showOverflowTooltip: true, align: 'center',
            formatter: (row, column, cellValue) => {return this.$util.toDateString(cellValue,"YYYY-MM-DD");}
          },
        ],
        paycommionid:'',
        qtyTotal:0,
        amountTotal:0,
        commissionAmountTotal:0,
        amountCnTotal:0,
        CommissionAmountCnTotal:0,
      };
    },
    computed: {
        // 表格高度
        tableHeight() {
          var fh = this.fixedHeight ? 'calc(100vh - 350px)' : void 0;
          return fh;
        },
        // 表格全屏时高度
        tableFullHeight() {
          var fh =  this.fixedHeight ? 'calc(100vh - 250px)' : null;
          return fh;
        },
      },
    created(){
      this.paycommionid = this.$route.query.paycommionid;
    },
    methods: {

      /* 表格数据源 */
      async datasource(params) {

        params.where.pageindex = params.page;
        params.where.pagesize = params.limit;

        //添加排序
        if(params.order.order == null || params.order.order == undefined){
          params.where.orderBys = [{ sort: "createDate", order: 1, }];
        }else{
          params.where.orderBys = [];
          params.where.orderBys.push({sort:params.sorter.column.sortable,order:params.order.order=='asc'?0:1});
        }

        if(!params.where.conditions)params.where.conditions = [];

        if(this.paycommionid){
          params.where.conditions.push({
            key:"payCommissionId",
            operator: 0,
            value:  this.paycommionid,
          })
        }

        console.log('params.where',params.where)

        let data = await QuerySaleoutorderByCondition(params.where);

        this.$nextTick(() => {
          this.$refs.table.doLayout();
        });

        return {
            list:data.items,
            count:data.totalrecords,
        };
      },

      /* 更新visible */
      updateVisible(value) {
        //更新父组件中的visible的值
        this.$emit('update:visible', value);
        //更新文件列表对像
      },

      /* 刷新表格 */
      reload(where) {
        if(this.$refs.table){
          this.$refs.table.reload({ where: where });
        }
      },

      //单击单号
      clickbillNo(row){
        // 采购订单
        removePageTab({ key: '/businesshandling/saleoutmanger' });
        this.$nextTick(() => {
          this.$router.push({path: '/businesshandling/saleoutmanger', query: { "orderNo": row.outOrderNo } });
        });
      },
  
  },
    
    /* 监听visible属性变化 */
    watch: {
      visible(visible) {
        if (visible) {
          //赋值this.form
          this.form = this.data;
          this.isUpdate = this.data.id !=null && this.data.id !=undefined;

          this.reload();
        } 
      }
    }
  };
  </script>